<!--
@fucntion: 教改项目-结题
-->
<template>
  <el-row class="teachingreform-conclusion">
    <el-col style="height:100%;">
      <table-panel v-show="!conclusionDlgVisible" :name="'教学改革研究与实践项目-项目结题'" :columns="conclusionColumns" :tableData="conclusionData" :showRowNumber="false" :multiSelection="true"
      :canExport="false" :customBtns="customBtns"
      :currentPage="conclusionCurrentPage" :totalNum="conclusionTotalNum" @page-change="onPageChange('conclusion',$event)" :pageSize="pageSize"
      @table-searching="onSearching('conclusion',$event)"
      @table-create="onCreate('conclusion',$event)" @table-edit="onEdit('conclusion', $event)"
      @table-delete="onDelete('conclusion',$event)" @table-export="onExport('conclusion',$event)"
      @selection-change="onSelectionChange('conclusion',$event)"></table-panel>
      <c-form v-show="conclusionDlgVisible" @form-close="onCloseForm"
      :formRecord="conclusionRecord"
      :formRules="conclusionRules"></c-form>
    </el-col>
  </el-row>
</template>
<script>
import TablePanel from "@/components/basic/TablePanel";
import {
  formModelInitFromTable,
  formRulesInitFromTable
} from "@/utils/formutils.js";
import { trueFalseRenderer } from "@/utils/tableutils.js";
import Form from "./conclusion/Form";

//meta info
var conclusion = "conclusion"; // 表格名称
var columnsAttr = "Columns"; // 列
var dataAttr = "Data"; // 数据
var selectionAttr = "Selection"; // 选中
var dlgVisibleAttr = "DlgVisible"; // 对话框
var formAttr = "Form";
var recordAttr = "Record"; // 表单模型
var rulesAttr = "Rules"; // 表单验证
var curPageAttr = "CurrentPage";// 分页-当前页
var totalNumAttr = "TotalNum";// 分页-总数
var qParamAttr = "QueryParams";// 查询参数

//
var conclusionColumns =[
  {
    prop:"xmsbbh",//外键
    label:"项目申报编号",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xmmc",
    label:"项目名称"
  },
  {
    prop:"jsbh",
    label:"项目主持人编号",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xm",//教师-姓名
    label:"项目主持人"
  },
  {
    prop:"sj",//教师-手机
    label:"联系电话"
  },
  {
    prop:"xybh",
    label:"项目所在部门编号",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xymc",// 学院-学院名称
    label:"项目所在部门"
  },
  {
    prop:"xmlx",
    label:"项目类型",
    hidden:true
  },
  {
    prop:"jsrwbh",//外键
    label:"建设任务编号",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xmjb",
    label:"项目级别",
    hidden:true
  },
  {
    prop:"xmbh",
    label:"项目编号"
  },
  {
    prop:"lxsj",
    label:"立项时间",
    type:"date",
    hidden:true
  },
  {
    prop:"jxsj",
    label:"结项时间",
    type:"date",
    hidden:true
  },
  {
    prop:"xmjtbh",
    label:"项目结题编号",
    outOfSearch:true,
    hidden:true
  }
];

export default {
  name:"Conclusion",
  components: {
    "table-panel": TablePanel,
    "c-form":Form
  },
  methods: {
    onSearching: function(tname, params) {// 查询
      var me = this;
      let url = "/static/data/conclusion.json"; 

      if(url !== "") {
        me[tname+qParamAttr] = {};
        me[tname+qParamAttr] = params;
        if (params.isAccurate) {
          me[tname+qParamAttr] = params.paramPairs;
        } else {
          me[tname+qParamAttr].keywords = params.query;
        }
        me.getRequest(url, me[tname+qParamAttr]).then(resp => {
            if(resp.status == 200) {
              me[tname+dataAttr] = resp.data.results;
              me[tname+totalNumAttr] = resp.data.total;
            }
        });
      }
    },
    onCreate: function(tname) {// 新增
      var me = this;
      me[tname+recordAttr] = formModelInitFromTable(me[tname+columnsAttr]);
      me[tname+recordAttr].sfqy = "1";// 创建时，有效否是选中的

      me[tname+dlgVisibleAttr] = true;
    },
    onEdit: function(tname, row) {// 编辑
      var me = this;
      me[tname + recordAttr]= row;
      me[tname + dlgVisibleAttr] = true;
    },
    onDelete: function(tname, row) {// 删除
      var me = this;
      me.$confirm("确定删除这条记录吗?", "提示", {
        type: "warning"
      }).then(() => {
        me.deleteRequest(`/????/${row.xybh}`).then((resp)=>{
          if(resp.status == 200) {
            me.$message.success("删除成功!");
            me.onSearching(conclusion,{});// 重新加载表格数据
          }else{
            me.$message.error("删除失败！");
          }
        });
      }).catch(() => {});
    },
    onExport: function(tname, params) {// 导出
      var me = this;
      me.$message.info("发送导出请求，返回下载路径");
    },
    onSelectionChange: function(tname, data) {// 选中改变
      var me = this;
      // 缓存记录，按照角色编号，查询对应的选中权限节点数组
      me[tname+selectionAttr] = data;
    },
    onConfirm: function(tname) {// 对话框-确认
      var me = this;
      // 验证信息
      var ret;
      me.$refs[tname + formAttr].validate((result, what)=>{
        ret = result;
      });
      if(!ret){
        me.$message.error("表单信息有误");
        return;
      }
      // 发送请求
      me.postRequest("/static/data/testSuc.json").then((resp)=>{
        if (resp.status == 200) {
          me.$message.success("提交成功！");
          //最后，隐藏对话框
          me[tname + dlgVisibleAttr] = false;
        } else {
          me.$message.error( "服务器发生错误，代码：" + resp.status);
        }
      });
    },
    onCloseForm:function(){
      var me = this;
      me[conclusion + dlgVisibleAttr] = false;
    }
  },
  data() {
    return {
      [conclusion + columnsAttr]: conclusionColumns, // 表格-列
      [conclusion + dataAttr]: [], // 表格的数据
      [conclusion + selectionAttr]: [], // 当前选中
      [conclusion + dlgVisibleAttr]: false, // 对话框是否可见
      [conclusion + recordAttr]: {}, // 表单模型
      [conclusion + rulesAttr]: {}, // 表单验证
      [conclusion + curPageAttr]:1,// 当前页
      [conclusion + totalNumAttr]:0,// 总数
      [conclusion + qParamAttr]:{},// 查询参数
      pageSize:20,// 每页数量
      customBtns:[{
        type:"success",
        text:"审批",
        icon:"el-icon-check",
        eventName:"table-approval"
      }]
    };
  },
  created: function() {
    var me = this;

    // 表单模型初始化
    me[conclusion+recordAttr] = formModelInitFromTable(me[conclusion+columnsAttr]);
    // 表单验证初始化
    me[conclusion+rulesAttr] = formRulesInitFromTable(me[conclusion+columnsAttr]);

  }
}
</script>
<style lang="scss">
.teachingreform-conclusion{
  height: 100%;
}
</style>
